package com.jmgd.cjlx.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jmgd.cjlx.constants.MainConstant;
import com.jmgd.cjlx.dao.JmgdMapper;
import com.jmgd.cjlx.dao.TYkbKhMapper;
import com.jmgd.cjlx.entity.*;
import com.jmgd.cjlx.param.ExcelExp;
import com.jmgd.cjlx.param.PhoneModel;
import com.jmgd.cjlx.service.JmgdService;
import com.jmgd.cjlx.util.*;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class JmgdServiceImpl implements JmgdService {
    @Autowired
    JmgdMapper jmgdMapper;

    @Autowired
    TYkbKhMapper tYkbKhMapper;


    @Override
    public String queryInvoiceYk(String beginDateTime, String endDateTime,String orderId) throws UnsupportedEncodingException {
        String parameter = "orderId="+(orderId==null?"":orderId)+"&beginTime="+(beginDateTime==null?"":beginDateTime)+"&endTime="+(endDateTime==null?"":endDateTime)+"&deptId=&fphm=";
        //System.out.println(parameter);
        //System.out.println(parameter+ MainConstant.secret);
        String sign = Md5.encryption(URLEncoder.encode(parameter,"UTF-8")+ MainConstant.secret);
        String url = MainConstant.hangxin_fp_url+MainConstant.api_orders+parameter.replaceAll(" ","%20")+"&sign="+sign;
        System.out.println(url);
        Map map = HttpClientUtil.doGet(url);
        //System.out.println(map.get("data"));
        JSONObject jsonObj = JSON.parseObject(map.get("data").toString());
        JSONArray data = jsonObj.getJSONArray("data");
        for(int index = 0, length = data.size(); index < length; index++) {
            //data.get(index);
            String orderIdResult = ((JSONObject) data.get(index)).get("orderId").toString();
            String kpDateResult = ((JSONObject) data.get(index)).get("kpDate").toString();
            System.out.println("单据号"+orderIdResult);
            System.out.println("开票日期"+kpDateResult);
            jmgdMapper.insertInvoiceYk(orderIdResult,kpDateResult);
        }
        return "success";
    }

    @Override
    public String queryTaxCodeByWare(String name, String time) throws UnsupportedEncodingException {
        String parameter = "name="+(name==null?"":name)+"&time="+(time==null?"":time);
        String sign = Md5.encryption(URLEncoder.encode(parameter,"UTF-8")+ MainConstant.secret);
        String url = MainConstant.hangxin_fp_url+MainConstant.api_products+parameter.replaceAll(" ","%20")+"&sign="+sign;
        System.out.println(url);
        Map map = HttpClientUtil.doGet(url);
        //System.out.println(map.get("data"));
        JSONObject jsonObj = JSON.parseObject(map.get("data").toString());
        JSONArray data = jsonObj.getJSONArray("data");
        for(int index = 0, length = data.size(); index < length; index++) {
            //data.get(index);
            String nameResult = ((JSONObject) data.get(index)).get("name").toString();
            String codeResult = ((JSONObject) data.get(index)).get("code").toString();
            System.out.println(nameResult);
            jmgdMapper.insertWareTaxCode(nameResult,codeResult);
        }
        jmgdMapper.updateWareTaxCode();
        return "success";
    }

    @Override
    public void ykbls() throws Exception {
        String url = "https://test-h5.mediext.com/gateway/api-member/api/v1/jm/outer/right/queryByDate";

        // 获取昨天的日期
        LocalDate yesterday = LocalDate.now().minusDays(1);

        // 创建格式化器
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        // 格式化昨天的日期
        String formattedDate = yesterday.format(formatter);


        // 创建数据
        Map<String, Object> data1 = new HashMap<>();
        data1.put("queryDate", formattedDate);

        // 创建 ObjectMapper 实例
        ObjectMapper objectMapper1 = new ObjectMapper();

        String jsonJm = DESUtils.encryptCBC(objectMapper1.writeValueAsString(data1),"a2s3x65d");
       // System.out.println(jsonJm);

//        Map<String, Object> data1 = new HashMap<>();
//        data1.put("dataEntString", jsonJm);
//
//        String json = objectMapper.writeValueAsString(data);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dataEntString",jsonJm);

        Map jsonMap = HttpClientUtil.doPost(url,null,jsonObject);
        System.out.println(jsonMap);


        // 创建 ObjectMapper 实例
      //  ObjectMapper objectMapper = new ObjectMapper();

        // 提取 "msg" 和 "statusCode"
        String msg = (String) jsonMap.get("msg");
        int statusCode = (int) jsonMap.get("statusCode");
        String data2 = (String)jsonMap.get("data");

        JSONObject data = JSONObject.parseObject(data2);

        // 提取 data 中的各个字段
        String code = data.getString("code");
        String message = data.getString("message");
       // Object subMessage = data.isNull("subMessage") ? null : data.get("subMessage");
        boolean success = data.getBoolean("success");

        // 提取 result 字段（它是一个 JSONArray）
        JSONArray resultArray = data.getJSONArray("result");

        // 打印解析后的字段
//        System.out.println("msg: " + msg);
//        System.out.println("statusCode: " + statusCode);
//        System.out.println("code: " + code);
//        System.out.println("message: " + message);
//        //System.out.println("subMessage: " + subMessage);
//        System.out.println("success: " + success);


        QueryWrapper<TYkbKh> queryWrapperQ = new QueryWrapper<>();
        queryWrapperQ.eq("collectdate",formattedDate);

        tYkbKhMapper.delete(queryWrapperQ);

        // 解析 result 数组
        for (int i = 0; i < resultArray.size(); i++) {
            JSONObject entry = resultArray.getJSONObject(i);
            String phoneNo = entry.getString("phoneNo");
            String insuredName = entry.getString("insuredName");
            String isDelete = entry.getString("isDelete");
            String collectDate = entry.getString("collectDate");
            System.out.println("PhoneNo: " + phoneNo + ", InsuredName: " + insuredName + ", IsDelete: " + isDelete);

            TYkbKh tYkbKh = new TYkbKh();
            tYkbKh.setPhoneno(phoneNo);
            tYkbKh.setInsuredname(insuredName);
            tYkbKh.setIsdelete(isDelete);
            tYkbKh.setCollectdate(collectDate);
            tYkbKhMapper.insert(tYkbKh);
        }

       // System.out.println();
    }

    @Override
    public void checkMemcardMobile() {
        List<MemcardEntity> memcardEntityList = jmgdMapper.selectMemcard();
        for(MemcardEntity memcardEntity:memcardEntityList){
            PhoneModel phoneModel = PhoneUtil.getPhoneModel(memcardEntity.getMobile());
            if(phoneModel != null){
                if(!"江门市".equals(phoneModel.getCityName()) && !"中山市".equals(phoneModel.getCityName()) && !"阳江市".equals(phoneModel.getCityName())){
                    String checkreason = phoneModel.getProvinceName()+"-"+ phoneModel.getCityName()+"-"+phoneModel.getCarrier();
                    jmgdMapper.insermemcardcheck(memcardEntity.getMemcardno(),checkreason);
                }
            }else{
                //String checkreason = "不是有效手机号码";
                //jmgdMapper.insermemcardcheck(memcardEntity.getMemcardno(),checkreason);
            }
        }

    }

    @Override
    public void createExcelLx(String idNoParam,String allowExcel) throws ParseException {
        List<HbyHbportalprivEntity> hbyHbportalprivEntityList = jmgdMapper.selectHbportalpriv(idNoParam,allowExcel);
        String qcPeriod = DateUtil.getMonthYYYYMM(-2);
        String qmPeriod = DateUtil.getMonthYYYYMM(-1);

        Date beginDate = DateUtil.getMonthFirstDay(-1);
        Date endDate = DateUtil.getMonthFirstDay(0);

        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");

        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


        for(HbyHbportalprivEntity hbyHbportalprivEntity:hbyHbportalprivEntityList){
            String idNo = hbyHbportalprivEntity.getIdNo();
            String comDesc = hbyHbportalprivEntity.getComDesc();
            List<HbyWareEntity> hbyWareEntityList = jmgdMapper.selectHbyWareList(idNo);
            List<HbyQcQmStoreEntity> hbyQcStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qcPeriod,comDesc);
            List<HbyQcQmStoreEntity> hbyQmStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qmPeriod,comDesc);
            List<HbyPurEntity> hbyPurEntityList = jmgdMapper.selectPur(idNo,beginDate,endDate);
            List<HbyDistEntity> hbyDistEntityList = jmgdMapper.selectDist(idNo,beginDate,endDate);
            List<HbySaleEntity> hbySaleEntityList = jmgdMapper.selectSale(idNo,beginDate,endDate);
            List<HbyStoreAdjustEntity> hbyStoreAdjustEntityList = jmgdMapper.selectStoreAjudst(idNo,beginDate,endDate,comDesc);



            //准备各个sheet数据(这里为演示设置为空)
            List<String[]> dataQyxxList = new ArrayList<>();
            List<String[]> dataQyscxxList = new ArrayList<>();
            try {
                //数据1
                List<String[]> dataset1 = new ArrayList<String[]>();
                //for (int i = 0; i < dataQyxxList .size(); i++) {
                for(HbyWareEntity hbyWareEntity:hbyWareEntityList){
                    String[] arr1 = new String[7];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr1[0] = hbyWareEntity.getIdNo();
                    arr1[1] = hbyWareEntity.getWareid().toString();
                    arr1[2] = hbyWareEntity.getWarename();
                    arr1[3] = hbyWareEntity.getWarespec();
                    arr1[4] = hbyWareEntity.getWareunit();
                    arr1[5] = hbyWareEntity.getFactoryname();
                    arr1[6] = hbyWareEntity.getAreaname();
                    dataset1.add(arr1);
                }
                //}
                //数据2
                List<String[]> dataset2 = new ArrayList<String[]>();
                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQcStoreEntityList) {
                    String[] arr2 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr2[0] = hbyQcQmStoreEntity.getIdNo();
                    arr2[1] = hbyQcQmStoreEntity.getBusno();
                    arr2[2] = hbyQcQmStoreEntity.getWareid().toString();
                    arr2[3] = hbyQcQmStoreEntity.getWarename();
                    arr2[4] = hbyQcQmStoreEntity.getWarespec();
                    arr2[5] = hbyQcQmStoreEntity.getFactoryname();
                    arr2[6] = hbyQcQmStoreEntity.getWareunit();
                    arr2[7] = hbyQcQmStoreEntity.getWareqty().toString();
                    arr2[8] = hbyQcQmStoreEntity.getMakeno();
                    arr2[9] = hbyQcQmStoreEntity.getPeriod();
                    dataset2.add(arr2);
                }

                //数据2
                List<String[]> dataset3 = new ArrayList<String[]>();
                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQmStoreEntityList) {
                    String[] arr3 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr3[0] = hbyQcQmStoreEntity.getIdNo();
                    arr3[1] = hbyQcQmStoreEntity.getBusno();
                    arr3[2] = hbyQcQmStoreEntity.getWareid().toString();
                    arr3[3] = hbyQcQmStoreEntity.getWarename();
                    arr3[4] = hbyQcQmStoreEntity.getWarespec();
                    arr3[5] = hbyQcQmStoreEntity.getFactoryname();
                    arr3[6] = hbyQcQmStoreEntity.getWareunit();
                    arr3[7] = hbyQcQmStoreEntity.getWareqty().toString();
                    arr3[8] = hbyQcQmStoreEntity.getMakeno();
                    arr3[9] = hbyQcQmStoreEntity.getPeriod();
                    dataset3.add(arr3);
                }


                //数据4
                List<String[]> dataset4 = new ArrayList<String[]>();
                for(HbyPurEntity hbyPurEntity:hbyPurEntityList) {
                    String[] arr4 = new String[11];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr4[0] = hbyPurEntity.getIdNo();
                    if("江门国大".equals(comDesc)){
                        arr4[1] = "国控国大（江门）医药有限公司";
                    }else if("国大健丰".equals(comDesc)){
                        arr4[1] = "国控国大健丰（江门）医药连锁有限公司";
                    }
                    arr4[2] = format2.format(hbyPurEntity.getAcceptdate());
                    arr4[3] = hbyPurEntity.getWareid().toString();
                    arr4[4] = hbyPurEntity.getWarename();
                    arr4[5] = hbyPurEntity.getWarespec();
                    arr4[6] = hbyPurEntity.getFactoryname();
                    arr4[7] = hbyPurEntity.getWareqty().toString();
                    arr4[8] = hbyPurEntity.getMakeno();
                    arr4[9] = hbyPurEntity.getVencusname();
                    arr4[10] = hbyPurEntity.getWareunit();

                    //arr4[10] = hbyPurEntity();
                    //  arr4[11] = hbyPurEntity.();
                    dataset4.add(arr4);
                }

                List<String[]> dataset5 = new ArrayList<String[]>();
                for(HbyDistEntity hbyDistEntity:hbyDistEntityList) {
                    String[] arr5 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr5[0] = hbyDistEntity.getIdNo();
                    arr5[1] = hbyDistEntity.getDistno();
                    arr5[2] = hbyDistEntity.getOrgname();
                    arr5[3] = format2.format(hbyDistEntity.getApplydate());
                    arr5[4] = hbyDistEntity.getWareid().toString();
                    arr5[5] = hbyDistEntity.getWarename();
                    arr5[6] = hbyDistEntity.getWarespec();
                    arr5[7] = hbyDistEntity.getWareunit();
                    arr5[8] = hbyDistEntity.getWareqty().toString();
                    arr5[9] = hbyDistEntity.getMakeno();
                    dataset5.add(arr5);
                }

                List<String[]> dataset6 = new ArrayList<String[]>();
                for(HbySaleEntity hbySaleEntity:hbySaleEntityList) {
                    String[] arr6 = new String[13];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr6[0] = hbySaleEntity.getIdNo();
                    arr6[1] = hbySaleEntity.getSaleno();
                    arr6[2] = format2.format(hbySaleEntity.getAccdate());
                    arr6[3] = hbySaleEntity.getOrgname();
                    arr6[4] = hbySaleEntity.getWareid().toString();
                    arr6[5] = hbySaleEntity.getWarename();
                    arr6[6] = hbySaleEntity.getWarespec();
                    arr6[7] = hbySaleEntity.getFactoryname();
                    arr6[8] = hbySaleEntity.getNetprice().toString();
                    arr6[9] = hbySaleEntity.getWareunit();
                    arr6[10] = hbySaleEntity.getWareqty().toString();
                    arr6[11] = hbySaleEntity.getMakeno();
                    arr6[12] = hbySaleEntity.getHospitalName();
                    dataset6.add(arr6);
                }


                List<String[]> dataset7 = new ArrayList<String[]>();
                for(HbyStoreAdjustEntity hbyStoreAdjustEntity:hbyStoreAdjustEntityList) {
                    String[] arr7 = new String[11];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    arr7[0] = hbyStoreAdjustEntity.getIdNo();
                    arr7[1] = hbyStoreAdjustEntity.getOrgname();
                    arr7[2] = format2.format(hbyStoreAdjustEntity.getTranDate());
                    arr7[3] = hbyStoreAdjustEntity.getDocNo();
                    arr7[4] = hbyStoreAdjustEntity.getWareid().toString();
                    arr7[5] = hbyStoreAdjustEntity.getWarename();
                    arr7[6] = hbyStoreAdjustEntity.getWarespec();
                    arr7[7] = hbyStoreAdjustEntity.getFactoryname();
                    arr7[8] = hbyStoreAdjustEntity.getWareunit();
                    arr7[9] = hbyStoreAdjustEntity.getWareqty().toString();
                    arr7[10] = hbyStoreAdjustEntity.getMakeno();
                    dataset7.add(arr7);
                }


                //}
                //设置sheet的表头与表名
                String[] handers1 = {"序号","商品编码","商品名称","规格","单位","生产企业","产地"};
                String[] handers2 = {"序号","业务机构","商品编码","商品名称","规格","生产企业","单位","商品数量","生产批号",//"有效期至","生产日期",
                        "库存日期"};
                String[] handers3 = {"序号","业务机构","商品编码","商品名称","规格","生产企业","单位","商品数量","生产批号",//"有效期至","生产日期",
                        "库存日期"};
                String[] handers4 = {"序号","业务机构","生效时间","商品编码","商品名称","规格","生产企业","入库数量","生产批号"//,"生产日期","有效期至"
                        ,"供应商名称","单位"};
                String[] handers5 = {"序号","单据号","业务机构","生效时间"//,"目标业务机构"
                        ,"商品编码","商品名称","规格","单位","商品数量","生产批号"//,"生产日期","有效期至"
                };
                String[] handers6 = {"序号","销售单号","会计日","业务机构名称","商品内码","商品名","规格","生产企业","单价","单位","数量","批号","医院名称"//,"科室名称","","",""
                };
                String[] handers7 = {"序号","业务机构","会计日","单据号","商品内码","商品名","规格","生产企业","单位","数量","批号"//,"科室名称","","",""
                };


                ExcelExp qyxxExp1 = new ExcelExp("授权商品", handers1,dataset1);
                ExcelExp qyxxExp2 = new ExcelExp("当月期初", handers2,dataset2);
                ExcelExp qyxxExp3 = new ExcelExp("当月期末", handers3,dataset3);
                ExcelExp qyxxExp4 = new ExcelExp("采购（供应商-仓库）", handers4,dataset4);
                ExcelExp qyxxExp5 = new ExcelExp("配送流向（仓库-门店）", handers5,dataset5);
                ExcelExp qyxxExp6 = new ExcelExp("销售（门店顾客）", handers6,dataset6);
                ExcelExp qyxxExp7 = new ExcelExp("盘盈盘亏单", handers7,dataset7);


                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
                mysheet.add(qyxxExp1);
                mysheet.add(qyxxExp2);
                mysheet.add(qyxxExp3);
                mysheet.add(qyxxExp4);
                mysheet.add(qyxxExp5);
                mysheet.add(qyxxExp6);
                mysheet.add(qyxxExp7);

                //fileName是你导出的文件名

                String fileName = null;
                if(null!=hbyHbportalprivEntity.getExcelFileName()){
                    fileName = hbyHbportalprivEntity.getExcelFileName();
                }else{
                    fileName = hbyHbportalprivEntity.getKeshang();
                }

                fileName = fileName+format.format(new Date());
                fileName = "D:\\GDFiles\\Lx\\"+fileName;

                //ExcelExportUtil是你设置Excel和下载控制的地方
                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
            }catch (Exception e){

            }

            System.out.println("生成成功！");
        }
    }


//    @Override
//    public void createExcelPurGjYJ() throws ParseException {
//        List<HbyHbportalprivEntity> hbyHbportalprivEntityList = jmgdMapper.selectHbportalpriv(idNoParam,allowExcel);
//        String qcPeriod = DateUtil.getMonthYYYYMM(-2);
//        String qmPeriod = DateUtil.getMonthYYYYMM(-1);
//
//        Date beginDate = DateUtil.getMonthFirstDay(-1);
//        Date endDate = DateUtil.getMonthFirstDay(0);
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
//
//        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for(HbyHbportalprivEntity hbyHbportalprivEntity:hbyHbportalprivEntityList){
//            String idNo = hbyHbportalprivEntity.getIdNo();
//            String comDesc = hbyHbportalprivEntity.getComDesc();
//            List<HbyWareEntity> hbyWareEntityList = jmgdMapper.selectHbyWareList(idNo);
//            List<HbyQcQmStoreEntity> hbyQcStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qcPeriod,comDesc);
//
//
//
//            //准备各个sheet数据(这里为演示设置为空)
//            List<String[]> dataQyxxList = new ArrayList<>();
//            List<String[]> dataQyscxxList = new ArrayList<>();
//            try {
//                //数据1
//                List<String[]> dataset1 = new ArrayList<String[]>();
//                //for (int i = 0; i < dataQyxxList .size(); i++) {
//                for(HbyWareEntity hbyWareEntity:hbyWareEntityList){
//                    String[] arr1 = new String[7];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr1[0] = hbyWareEntity.getIdNo();
//                    arr1[1] = hbyWareEntity.getWareid().toString();
//                    arr1[2] = hbyWareEntity.getWarename();
//                    arr1[3] = hbyWareEntity.getWarespec();
//                    arr1[4] = hbyWareEntity.getWareunit();
//                    arr1[5] = hbyWareEntity.getFactoryname();
//                    arr1[6] = hbyWareEntity.getAreaname();
//                    dataset1.add(arr1);
//                }
//                //}
//                //数据2
//                List<String[]> dataset2 = new ArrayList<String[]>();
//                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
//                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQcStoreEntityList) {
//                    String[] arr2 = new String[10];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr2[0] = hbyQcQmStoreEntity.getIdNo();
//                    arr2[1] = hbyQcQmStoreEntity.getBusno();
//                    arr2[2] = hbyQcQmStoreEntity.getWareid().toString();
//                    arr2[3] = hbyQcQmStoreEntity.getWarename();
//                    arr2[4] = hbyQcQmStoreEntity.getWarespec();
//                    arr2[5] = hbyQcQmStoreEntity.getFactoryname();
//                    arr2[6] = hbyQcQmStoreEntity.getWareunit();
//                    arr2[7] = hbyQcQmStoreEntity.getWareqty().toString();
//                    arr2[8] = hbyQcQmStoreEntity.getMakeno();
//                    arr2[9] = hbyQcQmStoreEntity.getPeriod();
//                    dataset2.add(arr2);
//                }
//
//                //}
//                //设置sheet的表头与表名
//                String[] handers1 = {"采购日期","供货企业","销售单号","入库单号","运输设备","运输开始时间","运输结束时间","温度记录","验收员名称","购进结论"};
//                String[] handers2 = {"生产批号","生产日期","有效期至","采购数量","本位码","包装规格"};
//
//
//
//                ExcelExp qyxxExp1 = new ExcelExp("sheet1", handers1,dataset1);
//                ExcelExp qyxxExp2 = new ExcelExp("sheet2", handers2,dataset2);
//
//
//                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//                mysheet.add(qyxxExp1);
//                mysheet.add(qyxxExp2);
//
//
//                //fileName是你导出的文件名
//
//                String fileName = "采购入库";
//
//                fileName = fileName+format.format(new Date());
//                fileName = "D:\\GDFiles\\Yj\\"+fileName;
//
//                //ExcelExportUtil是你设置Excel和下载控制的地方
//                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
//            }catch (Exception e){
//
//            }
//
//            System.out.println("采购入库文件生成成功！");
//        }
//    }
//
//
//    @Override
//    public void createExcelPurThYJ() throws ParseException {
//        List<HbyHbportalprivEntity> hbyHbportalprivEntityList = jmgdMapper.selectHbportalpriv(idNoParam,allowExcel);
//        String qcPeriod = DateUtil.getMonthYYYYMM(-2);
//        String qmPeriod = DateUtil.getMonthYYYYMM(-1);
//
//        Date beginDate = DateUtil.getMonthFirstDay(-1);
//        Date endDate = DateUtil.getMonthFirstDay(0);
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
//
//        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for(HbyHbportalprivEntity hbyHbportalprivEntity:hbyHbportalprivEntityList){
//            String idNo = hbyHbportalprivEntity.getIdNo();
//            String comDesc = hbyHbportalprivEntity.getComDesc();
//            List<HbyWareEntity> hbyWareEntityList = jmgdMapper.selectHbyWareList(idNo);
//            List<HbyQcQmStoreEntity> hbyQcStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qcPeriod,comDesc);
//
//
//
//            //准备各个sheet数据(这里为演示设置为空)
//            List<String[]> dataQyxxList = new ArrayList<>();
//            List<String[]> dataQyscxxList = new ArrayList<>();
//            try {
//                //数据1
//                List<String[]> dataset1 = new ArrayList<String[]>();
//                //for (int i = 0; i < dataQyxxList .size(); i++) {
//                for(HbyWareEntity hbyWareEntity:hbyWareEntityList){
//                    String[] arr1 = new String[7];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr1[0] = hbyWareEntity.getIdNo();
//                    arr1[1] = hbyWareEntity.getWareid().toString();
//                    arr1[2] = hbyWareEntity.getWarename();
//                    arr1[3] = hbyWareEntity.getWarespec();
//                    arr1[4] = hbyWareEntity.getWareunit();
//                    arr1[5] = hbyWareEntity.getFactoryname();
//                    arr1[6] = hbyWareEntity.getAreaname();
//                    dataset1.add(arr1);
//                }
//                //}
//                //数据2
//                List<String[]> dataset2 = new ArrayList<String[]>();
//                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
//                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQcStoreEntityList) {
//                    String[] arr2 = new String[10];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr2[0] = hbyQcQmStoreEntity.getIdNo();
//                    arr2[1] = hbyQcQmStoreEntity.getBusno();
//                    arr2[2] = hbyQcQmStoreEntity.getWareid().toString();
//                    arr2[3] = hbyQcQmStoreEntity.getWarename();
//                    arr2[4] = hbyQcQmStoreEntity.getWarespec();
//                    arr2[5] = hbyQcQmStoreEntity.getFactoryname();
//                    arr2[6] = hbyQcQmStoreEntity.getWareunit();
//                    arr2[7] = hbyQcQmStoreEntity.getWareqty().toString();
//                    arr2[8] = hbyQcQmStoreEntity.getMakeno();
//                    arr2[9] = hbyQcQmStoreEntity.getPeriod();
//                    dataset2.add(arr2);
//                }
//
//                //}
//                //设置sheet的表头与表名
//                String[] handers1 = {"退货日期","供货企业","出库单号","处理人","运输方式","承运人","运输开始时间","运输结束时间","起运温度","到达温度"};
//                String[] handers2 = {"生产批号","生产日期","有效期至","退货数量","退货原因","销售单号","本位码","包装规格"};
//
//
//
//                ExcelExp qyxxExp1 = new ExcelExp("sheet1", handers1,dataset1);
//                ExcelExp qyxxExp2 = new ExcelExp("sheet2", handers2,dataset2);
//
//
//                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//                mysheet.add(qyxxExp1);
//                mysheet.add(qyxxExp2);
//
//
//                //fileName是你导出的文件名
//
//                String fileName = "退货出库";
//
//                fileName = fileName+format.format(new Date());
//                fileName = "D:\\GDFiles\\Yj\\"+fileName;
//
//                //ExcelExportUtil是你设置Excel和下载控制的地方
//                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
//            }catch (Exception e){
//
//            }
//
//            System.out.println("采购退货文件生成成功！");
//        }
//    }

    @Override
    @Async
    public void createExcelSaleYJ(Date beginDate, Date endDate) throws ParseException {
        sale(beginDate,endDate,"50301");
        sale(beginDate,endDate,"0");
        //sale(beginDate,endDate,"6");
//            try {
//                //数据1
//                List<String[]> dataset1 = new ArrayList<String[]>();
//                //for (int i = 0; i < dataQyxxList .size(); i++) {
//                for(Map<String,Object> map:saleYJHList){
//                    String[] arr1 = new String[10];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr1[0] = map.get("SALE_DATE")==null?"":format1.format(format2.parse(map.get("SALE_DATE").toString()));
//                    arr1[1] = map.get("SALENO")==null?"":map.get("SALENO").toString();
//                    arr1[2] = map.get("VENCUS_NAME")==null?"":map.get("VENCUS_NAME").toString();
//                    arr1[3] = map.get("SALER")==null?"":map.get("SALER").toString();
//                    arr1[4] = map.get("TRANS_TYPE")==null?"":map.get("TRANS_TYPE").toString();
//                    arr1[5] = map.get("CHENG_YUN_PERSON")==null?"":map.get("CHENG_YUN_PERSON").toString();
//                    arr1[6] = map.get("BEGIN_DATE")==null?"":format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
//                    arr1[7] = map.get("END_DATE")==null?"":format1.format(format2.parse(map.get("END_DATE").toString()));
//                    arr1[8] = map.get("STARTUP_TEMP")==null?"":map.get("STARTUP_TEMP").toString();
//                    arr1[9] = map.get("ARRI_TEMP")==null?"":map.get("ARRI_TEMP").toString();
//                    dataset1.add(arr1);
//                }
//                //}
//                //数据2
//                List<String[]> dataset2 = new ArrayList<String[]>();
//                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
//                for(Map<String,Object> map:saleYJDList) {
//                    String[] arr2 = new String[9];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr2[0] = map.get("MAKENO")==null?"":map.get("MAKENO").toString();
//                    arr2[1] = map.get("PROD_DATE")==null?"":format1.format(format2.parse(map.get("PROD_DATE").toString()));
//                    arr2[2] = map.get("VALID_DATE")==null?"":format1.format(format2.parse(map.get("VALID_DATE").toString()));
//                    arr2[3] = map.get("WARE_QTY")==null?"":map.get("WARE_QTY").toString();
//                    arr2[4] = map.get("BWM")==null?"":map.get("BWM").toString();
//                    arr2[5] = map.get("WARE_SPEC")==null?"":map.get("WARE_SPEC").toString();
//                    //arr2[6] = map.get("SALENO")==null?"":map.get("SALENO").toString();
//                    //arr2[7] = map.get("WAREID")==null?"":map.get("WAREID").toString();
//                    //arr2[8] = map.get("SALE_DATE")==null?"":map.get("SALE_DATE").toString();
//                    dataset2.add(arr2);
//                }
//
//                //}
//                //设置sheet的表头与表名
//                String[] handers1 = {"销售时间","销售单号","采购企业","销售员","运输方式","承运人","运输开始时间","运输结束时间","起运温度","到达温度"};
//
//                String[] handers2 = {"生产批号","生产日期","有效期至","销售数量","本位码","包装规格"};
//
//
//
//                ExcelExp qyxxExp1 = new ExcelExp("sheet1", handers1,dataset1);
//                ExcelExp qyxxExp2 = new ExcelExp("sheet2", handers2,dataset2);
//
//
//                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//                mysheet.add(qyxxExp1);
//                mysheet.add(qyxxExp2);
//
//
//                //fileName是你导出的文件名
//
//                String fileName1 = "销售出库";
//
//                fileName = fileName+format3.format(new Date());
//                fileName = "D:\\GDFiles\\Yj\\"+fileName1;
//
//                //ExcelExportUtil是你设置Excel和下载控制的地方
//                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
//            }catch (Exception e){
//                e.printStackTrace();
//            }
//
//            System.out.println("销售出库文件生成成功！");
//    }

//
//    @Override
//    public void createExcelSaleThYJ() throws ParseException {
//        List<HbyHbportalprivEntity> hbyHbportalprivEntityList = jmgdMapper.selectHbportalpriv(idNoParam,allowExcel);
//        String qcPeriod = DateUtil.getMonthYYYYMM(-2);
//        String qmPeriod = DateUtil.getMonthYYYYMM(-1);
//
//        Date beginDate = DateUtil.getMonthFirstDay(-1);
//        Date endDate = DateUtil.getMonthFirstDay(0);
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
//
//        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for(HbyHbportalprivEntity hbyHbportalprivEntity:hbyHbportalprivEntityList){
//            String idNo = hbyHbportalprivEntity.getIdNo();
//            String comDesc = hbyHbportalprivEntity.getComDesc();
//            List<HbyWareEntity> hbyWareEntityList = jmgdMapper.selectHbyWareList(idNo);
//            List<HbyQcQmStoreEntity> hbyQcStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qcPeriod,comDesc);
//
//
//
//            //准备各个sheet数据(这里为演示设置为空)
//            List<String[]> dataQyxxList = new ArrayList<>();
//            List<String[]> dataQyscxxList = new ArrayList<>();
//            try {
//                //数据1
//                List<String[]> dataset1 = new ArrayList<String[]>();
//                //for (int i = 0; i < dataQyxxList .size(); i++) {
//                for(HbyWareEntity hbyWareEntity:hbyWareEntityList){
//                    String[] arr1 = new String[7];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr1[0] = hbyWareEntity.getIdNo();
//                    arr1[1] = hbyWareEntity.getWareid().toString();
//                    arr1[2] = hbyWareEntity.getWarename();
//                    arr1[3] = hbyWareEntity.getWarespec();
//                    arr1[4] = hbyWareEntity.getWareunit();
//                    arr1[5] = hbyWareEntity.getFactoryname();
//                    arr1[6] = hbyWareEntity.getAreaname();
//                    dataset1.add(arr1);
//                }
//                //}
//                //数据2
//                List<String[]> dataset2 = new ArrayList<String[]>();
//                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
//                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQcStoreEntityList) {
//                    String[] arr2 = new String[10];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr2[0] = hbyQcQmStoreEntity.getIdNo();
//                    arr2[1] = hbyQcQmStoreEntity.getBusno();
//                    arr2[2] = hbyQcQmStoreEntity.getWareid().toString();
//                    arr2[3] = hbyQcQmStoreEntity.getWarename();
//                    arr2[4] = hbyQcQmStoreEntity.getWarespec();
//                    arr2[5] = hbyQcQmStoreEntity.getFactoryname();
//                    arr2[6] = hbyQcQmStoreEntity.getWareunit();
//                    arr2[7] = hbyQcQmStoreEntity.getWareqty().toString();
//                    arr2[8] = hbyQcQmStoreEntity.getMakeno();
//                    arr2[9] = hbyQcQmStoreEntity.getPeriod();
//                    dataset2.add(arr2);
//                }
//
//                //}
//                //设置sheet的表头与表名
//                String[] handers1 = {"退货日期","退货企业名称","入库单号","运输设备","运输开始时间","运输结束时间","温度记录","验收员名称","购进结论"};
//
//                String[] handers2 = {"生产批号","生产日期","有效期至","退货数量","退货原因","销售单号","本位码","包装规格"};
//
//
//
//                ExcelExp qyxxExp1 = new ExcelExp("sheet1", handers1,dataset1);
//                ExcelExp qyxxExp2 = new ExcelExp("sheet2", handers2,dataset2);
//
//
//                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//                mysheet.add(qyxxExp1);
//                mysheet.add(qyxxExp2);
//
//
//                //fileName是你导出的文件名
//
//                String fileName = "销售退货入库";
//
//                fileName = fileName+format.format(new Date());
//                fileName = "D:\\GDFiles\\Yj\\"+fileName;
//
//                //ExcelExportUtil是你设置Excel和下载控制的地方
//                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
//            }catch (Exception e){
//
//            }
//
//            System.out.println("销售退货入库文件生成成功！");
//        }
//    }
//
//
//    @Override
//    public void createExcelStockYJ() throws ParseException {
//        List<HbyHbportalprivEntity> hbyHbportalprivEntityList = jmgdMapper.selectHbportalpriv(idNoParam,allowExcel);
//        String qcPeriod = DateUtil.getMonthYYYYMM(-2);
//        String qmPeriod = DateUtil.getMonthYYYYMM(-1);
//
//        Date beginDate = DateUtil.getMonthFirstDay(-1);
//        Date endDate = DateUtil.getMonthFirstDay(0);
//
//        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
//
//        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//        for(HbyHbportalprivEntity hbyHbportalprivEntity:hbyHbportalprivEntityList){
//            String idNo = hbyHbportalprivEntity.getIdNo();
//            String comDesc = hbyHbportalprivEntity.getComDesc();
//            List<HbyWareEntity> hbyWareEntityList = jmgdMapper.selectHbyWareList(idNo);
//            List<HbyQcQmStoreEntity> hbyQcStoreEntityList = jmgdMapper.selectQcQmStore(idNo,qcPeriod,comDesc);
//
//
//
//            //准备各个sheet数据(这里为演示设置为空)
//            List<String[]> dataQyxxList = new ArrayList<>();
//            List<String[]> dataQyscxxList = new ArrayList<>();
//            try {
//                //数据1
//                List<String[]> dataset1 = new ArrayList<String[]>();
//                //for (int i = 0; i < dataQyxxList .size(); i++) {
//                for(HbyWareEntity hbyWareEntity:hbyWareEntityList){
//                    String[] arr1 = new String[7];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr1[0] = hbyWareEntity.getIdNo();
//                    arr1[1] = hbyWareEntity.getWareid().toString();
//                    arr1[2] = hbyWareEntity.getWarename();
//                    arr1[3] = hbyWareEntity.getWarespec();
//                    arr1[4] = hbyWareEntity.getWareunit();
//                    arr1[5] = hbyWareEntity.getFactoryname();
//                    arr1[6] = hbyWareEntity.getAreaname();
//                    dataset1.add(arr1);
//                }
//                //}
//                //数据2
//                List<String[]> dataset2 = new ArrayList<String[]>();
//                //   for (int i = 0; i < dataQyscxxList .size(); i++) {
//                for(HbyQcQmStoreEntity hbyQcQmStoreEntity:hbyQcStoreEntityList) {
//                    String[] arr2 = new String[10];//有几列就写几
//                    //如果数据不为空则赋值(这里就是循环每行的数据)
//                    arr2[0] = hbyQcQmStoreEntity.getIdNo();
//                    arr2[1] = hbyQcQmStoreEntity.getBusno();
//                    arr2[2] = hbyQcQmStoreEntity.getWareid().toString();
//                    arr2[3] = hbyQcQmStoreEntity.getWarename();
//                    arr2[4] = hbyQcQmStoreEntity.getWarespec();
//                    arr2[5] = hbyQcQmStoreEntity.getFactoryname();
//                    arr2[6] = hbyQcQmStoreEntity.getWareunit();
//                    arr2[7] = hbyQcQmStoreEntity.getWareqty().toString();
//                    arr2[8] = hbyQcQmStoreEntity.getMakeno();
//                    arr2[9] = hbyQcQmStoreEntity.getPeriod();
//                    dataset2.add(arr2);
//                }
//
//                //}
//                //设置sheet的表头与表名
//                String[] handers1 = {"库存盘点截止时间"};
//
//                String[] handers2 = {"生产批号","生产日期","有效期至","库存数量","本位码","包装规格"};
//
//
//
//                ExcelExp qyxxExp1 = new ExcelExp("sheet1", handers1,dataset1);
//                ExcelExp qyxxExp2 = new ExcelExp("sheet2", handers2,dataset2);
//
//
//                List<ExcelExp> mysheet = new ArrayList<ExcelExp>();
//                mysheet.add(qyxxExp1);
//                mysheet.add(qyxxExp2);
//
//
//                //fileName是你导出的文件名
//
//                String fileName = "库存上报";
//
//                fileName = fileName+format.format(new Date());
//                fileName = "D:\\GDFiles\\Yj\\"+fileName;
//
//                //ExcelExportUtil是你设置Excel和下载控制的地方
//                ExcelExportUtil.exportManySheetExcel(fileName,mysheet,null); //生成sheet
//            }catch (Exception e){
//
//            }
//
//            System.out.println("库存上报文件生成成功！");
//        }
//    }
    }

    private void sale(Date beginDate, Date endDate,String stockNo) throws ParseException {

        while(beginDate.compareTo(endDate)<0) {
            List<Map<String, Object>> saleYJHList = null;
            List<Map<String, Object>> saleYJDList = null;
            if (stockNo.equals("50301")) {
                saleYJHList = jmgdMapper.selectExcelSaleYJH(beginDate, dateAddOne(beginDate,1), "零售");
                saleYJDList = jmgdMapper.selectExcelSaleYJD2(beginDate, dateAddOne(beginDate,1), "零售");
            } else {
                saleYJHList = jmgdMapper.selectExcelSaleN50301YJH(beginDate, dateAddOne(beginDate,1), "零售");
                saleYJDList = jmgdMapper.selectExcelSaleYJDN2(beginDate, dateAddOne(beginDate,1), "零售");
            }
            if (saleYJHList.size()>0) {
                //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(beginDate,endDate);
                SimpleDateFormat format3 = new SimpleDateFormat("yyyyMMdd");

                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

                // 1.声明文件名称
                String fileName = "pifachuku_jiangmen";
                String stockName = "";
                //String fileName1 = "销售出库";
                if (stockNo.equals("50301")) {
                    stockName = "零售仓";
                    fileName = "零售" + fileName;
                } else {
                    stockName = "批发仓";
                    fileName = "批发" + fileName;
                }
                //else if(stockNo.equals("50306")){
                //  stockName = "50306临时仓";
                //}


                fileName = fileName + format3.format(beginDate);
                fileName = "D:\\GDFiles\\Yj\\" + stockName + "\\" + fileName;


                // 2.创建dom对象
                Document document = DocumentHelper.createDocument();

                // 3.添加节点，根据需求添加，这里我只是设置了一个head节点，下面有name和age两个子节点
                Element head = document.addElement("jh", "http://cmsland.com/yjj_qyjk_pfck.xsd");
                //head.addAttribute("xmlns", "http://cmsland.com/yjj_qyjk_pfck.xsd");
                for (Map<String, Object> map : saleYJHList) {
                    System.out.println(map.get("SALENO") == null ? "" : map.get("SALENO").toString());
                    String[] arr1 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    Element dj = head.addElement("dj");
                    dj.addAttribute("djbh", map.get("SALENO").toString());
                    dj.addAttribute("ckrq", format1.format(format2.parse(map.get("SALE_DATE").toString())));
                    dj.addAttribute("cgqy", map.get("VENCUS_NAME").toString());

                    //List<Map<String, Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(map.get("SALENO").toString(), format2.parse(map.get("SALE_DATE").toString()), map.get("STOCK_TYPE").toString());

                    String searchSaleno = map.get("SALENO").toString();
                    String stockType = map.get("STOCK_TYPE").toString();

                    String searchDate = format2.format(map.get("SALE_DATE"));

                    List<Map<String, Object>> result =  saleYJDList.stream()
                            .filter(row -> searchDate.equals(format2.format(row.get("SALE_DATE"))))
                            .filter(row -> searchSaleno.equals(row.get("SALENO")))
                            .filter(row -> stockType.equals(row.get("STOCK_TYPE"))).collect(Collectors.toList());



                    for (Map<String, Object> mapd : result) {
                        Element tm = dj.addElement("tm");
                        tm.addAttribute("bwm", mapd.get("BWM") == null ? "" : mapd.get("BWM").toString());
                        tm.addAttribute("bzgg", mapd.get("WARE_SPEC") == null ? "" : mapd.get("WARE_SPEC").toString());
                        tm.addAttribute("scph", mapd.get("MAKENO") == null ? "" : mapd.get("MAKENO").toString());
                        tm.addAttribute("scrq", mapd.get("PROD_DATE") == null ? "" : format1.format(format2.parse(mapd.get("PROD_DATE").toString())));
                        tm.addAttribute("yxqz", mapd.get("VALID_DATE") == null ? "" : format1.format(format2.parse(mapd.get("VALID_DATE").toString())));
                        tm.addAttribute("sl", mapd.get("WARE_QTY") == null ? "" : mapd.get("WARE_QTY").toString());
                    }
/*

            arr1[0] = map.get("SALE_DATE") == null ? "" : format1.format(format2.parse(map.get("SALE_DATE").toString()));
            arr1[1] = map.get("SALENO") == null ? "" : map.get("SALENO").toString();
            arr1[2] = map.get("VENCUS_NAME") == null ? "" : map.get("VENCUS_NAME").toString();
            arr1[3] = map.get("SALER") == null ? "" : map.get("SALER").toString();
            arr1[4] = map.get("TRANS_TYPE") == null ? "" : map.get("TRANS_TYPE").toString();
            arr1[5] = map.get("CHENG_YUN_PERSON") == null ? "" : map.get("CHENG_YUN_PERSON").toString();
            arr1[6] = map.get("BEGIN_DATE") == null ? "" : format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
            arr1[7] = map.get("END_DATE") == null ? "" : format1.format(format2.parse(map.get("END_DATE").toString()));
            arr1[8] = map.get("STARTUP_TEMP") == null ? "" : map.get("STARTUP_TEMP").toString();
            arr1[9] = map.get("ARRI_TEMP") == null ? "" : map.get("ARRI_TEMP").toString();*/
                }


                // Element age = head.addElement("age");
                //age.addText("18");

                // 4、格式化模板
                //OutputFormat format = OutputFormat.createCompactFormat();
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setEncoding("GBK");

                // 5、生成xml文件
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                try {
                    XMLWriter writer = new XMLWriter(out, format);
                    writer.write(document);
                    writer.close();
                } catch (IOException e) {
                    System.out.println("生成xml文件失败。文件名【" + fileName + "】");
                }

                // 6、生成的XML文件
                // 7、利用文件输出流输出到文件， 文件输出到了您的项目根目录下了
                try (FileOutputStream fos = new FileOutputStream(fileName + ".xml")) {
                    fos.write(out.toByteArray());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            //System.out.println("生成药监批发配送xml文件成功");
            beginDate = dateAddOne(beginDate,1);
        }
    }


    @Override
    @Async
    public void createExcelSaleReturnYJ(Date beginDate, Date endDate) throws ParseException {
        returnSale(beginDate, endDate,"50301");
        returnSale(beginDate, endDate,"0");
        //returnSale(beginDate, endDate,"6");
    }

    private void returnSale(Date beginDate, Date endDate,String stockNo) throws ParseException {
        while(beginDate.compareTo(endDate)<0) {
            List<Map<String, Object>> saleYJHList = null;
            List<Map<String, Object>> saleYJDList = null;
            if(stockNo.equals("50301")) {
                saleYJHList = jmgdMapper.selectExcelReturnSaleYJH(beginDate, dateAddOne(beginDate,1), "零售");
                saleYJDList = jmgdMapper.selectExcelReturnSaleYJD2(beginDate, dateAddOne(beginDate,1), "零售");
            }else{
                saleYJHList = jmgdMapper.selectExcelReturnSaleN50301YJH(beginDate, dateAddOne(beginDate,1), "零售");
                saleYJDList = jmgdMapper.selectExcelReturnSaleYJDN2(beginDate, dateAddOne(beginDate,1), "零售");
            }

            if(saleYJHList.size()>0) {
                //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(beginDate,endDate);
                SimpleDateFormat format3 = new SimpleDateFormat("yyyyMMdd");

                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

                // 1.声明文件名称
                String fileName = "pifatuihuoruku_jiangmen";
                //String fileName1 = "销售出库";
                String stockName = "";
                //String fileName1 = "销售出库";

                if (stockNo.equals("50301")) {
                    stockName = "零售仓";
                    fileName = "零售" + fileName;
                } else {
                    stockName = "批发仓";
                    fileName = "批发" + fileName;
                }
                //else if(stockNo.equals("50306")){
                //  stockName = "50306临时仓";
                //}


                fileName = fileName + format3.format(beginDate);
                fileName = "D:\\GDFiles\\Yj\\" + stockName + "\\" + fileName;

                // 2.创建dom对象
                Document document = DocumentHelper.createDocument();

                // 3.添加节点，根据需求添加，这里我只是设置了一个head节点，下面有name和age两个子节点
                Element head = document.addElement("jh", "http://cmsland.com/yjj_qyjk_pfthrk.xsd");
                //head.addAttribute("xmlns", "http://cmsland.com/yjj_qyjk_pfck.xsd");
                for (Map<String, Object> map : saleYJHList) {
                    System.out.println(map.get("SALENO") == null ? "" : map.get("SALENO").toString());

                    String[] arr1 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    Element dj = head.addElement("dj");
                    dj.addAttribute("djbh", map.get("SALENO").toString());
                    dj.addAttribute("rqrq", format1.format(format2.parse(map.get("SALE_DATE").toString())));
                    dj.addAttribute("thqy", map.get("VENCUS_NAME").toString());
                    dj.addAttribute("clr", "李协灿");
                    dj.addAttribute("ysjl", "正常");

                    //List<Map<String, Object>> saleYJDList = jmgdMapper.selectExcelReturnSaleYJD(map.get("SALENO").toString(), format2.parse(map.get("SALE_DATE").toString()), map.get("STOCK_TYPE").toString());

                    String searchSaleno = map.get("SALENO").toString();
                    String stockType = map.get("STOCK_TYPE").toString();

                    String searchDate = format2.format(map.get("SALE_DATE"));
                    List<Map<String, Object>> result =  saleYJDList.stream()
                            .filter(row -> searchDate.equals(format2.format(row.get("SALE_DATE"))))
                            .filter(row -> searchSaleno.equals(row.get("SALENO")))
                            .filter(row -> stockType.equals(row.get("STOCK_TYPE"))).collect(Collectors.toList());


                    for (Map<String, Object> map1 : result) {
                        Element tm = dj.addElement("tm");
                        tm.addAttribute("bwm", map1.get("BWM") == null ? "" : map1.get("BWM").toString());
                        tm.addAttribute("bzgg", map1.get("WARE_SPEC") == null ? "" : map1.get("WARE_SPEC").toString());
                        tm.addAttribute("scph", map1.get("MAKENO") == null ? "" : map1.get("MAKENO").toString());
                        tm.addAttribute("scrq", map1.get("PROD_DATE") == null ? "" : format1.format(format2.parse(map1.get("PROD_DATE").toString())));
                        tm.addAttribute("yxqz", map1.get("VALID_DATE") == null ? "" : format1.format(format2.parse(map1.get("VALID_DATE").toString())));
                        tm.addAttribute("sl", map1.get("WARE_QTY") == null ? "" : map1.get("WARE_QTY").toString());
                        tm.addAttribute("yy", "配送退货");
                        tm.addAttribute("xsdh", map1.get("SALENO") == null ? "" : map1.get("SALENO").toString());
                    }
/*

            arr1[0] = map.get("SALE_DATE") == null ? "" : format1.format(format2.parse(map.get("SALE_DATE").toString()));
            arr1[1] = map.get("SALENO") == null ? "" : map.get("SALENO").toString();
            arr1[2] = map.get("VENCUS_NAME") == null ? "" : map.get("VENCUS_NAME").toString();
            arr1[3] = map.get("SALER") == null ? "" : map.get("SALER").toString();
            arr1[4] = map.get("TRANS_TYPE") == null ? "" : map.get("TRANS_TYPE").toString();
            arr1[5] = map.get("CHENG_YUN_PERSON") == null ? "" : map.get("CHENG_YUN_PERSON").toString();
            arr1[6] = map.get("BEGIN_DATE") == null ? "" : format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
            arr1[7] = map.get("END_DATE") == null ? "" : format1.format(format2.parse(map.get("END_DATE").toString()));
            arr1[8] = map.get("STARTUP_TEMP") == null ? "" : map.get("STARTUP_TEMP").toString();
            arr1[9] = map.get("ARRI_TEMP") == null ? "" : map.get("ARRI_TEMP").toString();*/
                }


                // Element age = head.addElement("age");
                //age.addText("18");

                // 4、格式化模板
                //OutputFormat format = OutputFormat.createCompactFormat();
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setEncoding("GBK");

                // 5、生成xml文件
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                try {
                    XMLWriter writer = new XMLWriter(out, format);
                    writer.write(document);
                    writer.close();
                } catch (IOException e) {
                    System.out.println("生成xml文件失败。文件名【" + fileName + "】");
                }

                // 6、生成的XML文件
                // 7、利用文件输出流输出到文件， 文件输出到了您的项目根目录下了
                try (FileOutputStream fos = new FileOutputStream(fileName + ".xml")) {
                    fos.write(out.toByteArray());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            beginDate = dateAddOne(beginDate,1);

        }
        //System.out.println("生成销售退货xml文件成功");
    }

    @Override
    @Async
    public void createExcelPurYJ(Date beginDate, Date endDate) throws ParseException {
        pur(beginDate,endDate,"50301");
        pur(beginDate,endDate,"0");
    }

    private void pur(Date beginDate, Date endDate,String stockNo) throws ParseException {
        while(beginDate.compareTo(endDate)<0) {

            List<Map<String, Object>> saleYJHList = null;
            List<Map<String, Object>> saleYJDList = null;
            if(stockNo.equals("50301")){
                saleYJHList = jmgdMapper.selectExcelPurYJH(beginDate, dateAddOne(beginDate,1),"零售");
                saleYJDList = jmgdMapper.selectExcelPurYJD2(beginDate, dateAddOne(beginDate,1), "零售");
            }else{
                saleYJHList = jmgdMapper.selectExcelPurN50301YJH(beginDate, dateAddOne(beginDate,1),"零售");
                saleYJDList = jmgdMapper.selectExcelPurYJDN2(beginDate, dateAddOne(beginDate,1), "零售");
            }

            if(saleYJHList.size()>0) {
                //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(beginDate,endDate);
                SimpleDateFormat format3 = new SimpleDateFormat("yyyyMMdd");

                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

                // 1.声明文件名称
                String fileName = "caigouruku_jiangmen";
                //String fileName1 = "销售出库";

                String stockName = "";
                //String fileName1 = "销售出库";

                if (stockNo.equals("50301")) {
                    stockName = "零售仓";
                    fileName = "零售" + fileName;
                } else {
                    stockName = "批发仓";
                    fileName = "批发" + fileName;
                }


                fileName = fileName + format3.format(beginDate);
                fileName = "D:\\GDFiles\\Yj\\" + stockName + "\\" + fileName;


                // 2.创建dom对象
                Document document = DocumentHelper.createDocument();

                // 3.添加节点，根据需求添加，这里我只是设置了一个head节点，下面有name和age两个子节点
                Element head = document.addElement("jh", "http://cmsland.com/yjj_qyjk_cgrk.xsd");
                //head.addAttribute("xmlns", "http://cmsland.com/yjj_qyjk_pfck.xsd");
                for (Map<String, Object> map : saleYJHList) {
                    System.out.println(map.get("SALENO") == null ? "" : map.get("SALENO").toString());

                    String[] arr1 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    Element dj = head.addElement("dj");
                    dj.addAttribute("djbh", map.get("SALENO").toString());
                    dj.addAttribute("rqrq", format1.format(format2.parse(map.get("SALE_DATE").toString())));
                    dj.addAttribute("ghqy", map.get("VENCUS_NAME").toString());
                    dj.addAttribute("xsdh", map.get("SALENO").toString());
                    dj.addAttribute("clr", "李协灿");
                    dj.addAttribute("ysjl", "合格");

                    //List<Map<String, Object>> saleYJDList = jmgdMapper.selectExcelPurYJD(map.get("SALENO").toString(), format2.parse(map.get("SALE_DATE").toString()), map.get("STOCK_TYPE").toString());

                    String searchSaleno = map.get("SALENO").toString();
                    String stockType = map.get("STOCK_TYPE").toString();

                    String searchDate = format2.format(map.get("SALE_DATE"));
                    List<Map<String, Object>> result =  saleYJDList.stream()
                            .filter(row -> searchDate.equals(format2.format(row.get("SALE_DATE"))))
                            .filter(row -> searchSaleno.equals(row.get("SALENO")))
                            .filter(row -> stockType.equals(row.get("STOCK_TYPE"))).collect(Collectors.toList());

                    for (Map<String, Object> map1 : result) {
                        Element tm = dj.addElement("tm");
                        tm.addAttribute("bwm", map1.get("BWM") == null ? "" : map1.get("BWM").toString());
                        tm.addAttribute("bzgg", map1.get("WARE_SPEC") == null ? "" : map1.get("WARE_SPEC").toString());
                        tm.addAttribute("scph", map1.get("MAKENO") == null ? "" : map1.get("MAKENO").toString());
                        tm.addAttribute("scrq", map1.get("PROD_DATE") == null ? "" : format1.format(format2.parse(map1.get("PROD_DATE").toString())));
                        tm.addAttribute("yxqz", map1.get("VALID_DATE") == null ? "" : format1.format(format2.parse(map1.get("VALID_DATE").toString())));
                        tm.addAttribute("sl", map1.get("WARE_QTY") == null ? "" : map1.get("WARE_QTY").toString());
                    }
/*

            arr1[0] = map.get("SALE_DATE") == null ? "" : format1.format(format2.parse(map.get("SALE_DATE").toString()));
            arr1[1] = map.get("SALENO") == null ? "" : map.get("SALENO").toString();
            arr1[2] = map.get("VENCUS_NAME") == null ? "" : map.get("VENCUS_NAME").toString();
            arr1[3] = map.get("SALER") == null ? "" : map.get("SALER").toString();
            arr1[4] = map.get("TRANS_TYPE") == null ? "" : map.get("TRANS_TYPE").toString();
            arr1[5] = map.get("CHENG_YUN_PERSON") == null ? "" : map.get("CHENG_YUN_PERSON").toString();
            arr1[6] = map.get("BEGIN_DATE") == null ? "" : format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
            arr1[7] = map.get("END_DATE") == null ? "" : format1.format(format2.parse(map.get("END_DATE").toString()));
            arr1[8] = map.get("STARTUP_TEMP") == null ? "" : map.get("STARTUP_TEMP").toString();
            arr1[9] = map.get("ARRI_TEMP") == null ? "" : map.get("ARRI_TEMP").toString();*/
                }


                // Element age = head.addElement("age");
                //age.addText("18");

                // 4、格式化模板
                //OutputFormat format = OutputFormat.createCompactFormat();
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setEncoding("GBK");

                // 5、生成xml文件
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                try {
                    XMLWriter writer = new XMLWriter(out, format);
                    writer.write(document);
                    writer.close();
                } catch (IOException e) {
                    System.out.println("生成xml文件失败。文件名【" + fileName + "】");
                }

                // 6、生成的XML文件
                // 7、利用文件输出流输出到文件， 文件输出到了您的项目根目录下了
                try (FileOutputStream fos = new FileOutputStream(fileName + ".xml")) {
                    fos.write(out.toByteArray());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            beginDate = dateAddOne(beginDate,1);

        }

        // System.out.println("生成采购xml文件成功");
    }



    @Override
    @Async
    public void createExcelPurReturnYJ(Date beginDate, Date endDate) throws ParseException {
        purReturn(beginDate,endDate,"50301");
        purReturn(beginDate,endDate,"0");
    }


    private void purReturn(Date beginDate, Date endDate,String stockNo) throws ParseException {

        while(beginDate.compareTo(endDate)<0) {
            List<Map<String, Object>> saleYJHList = null;
            List<Map<String, Object>> saleYJDList = null;

            if(stockNo.equals("50301")){
                saleYJHList = jmgdMapper.selectExcelReturnPurYJH(beginDate, dateAddOne(beginDate,1),"零售");
                saleYJDList = jmgdMapper.selectExcelReturnPurYJD2(beginDate, dateAddOne(beginDate,1),"零售");
            }else{
                saleYJHList = jmgdMapper.selectExcelReturnPurN50301YJH(beginDate, dateAddOne(beginDate,1),"零售");
                saleYJDList = jmgdMapper.selectExcelReturnPurYJDN2(beginDate, dateAddOne(beginDate,1),"零售");
            }

            if(saleYJHList.size()>0) {

                //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(beginDate,endDate);
                SimpleDateFormat format3 = new SimpleDateFormat("yyyyMMdd");

                SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

                // 1.声明文件名称
                String fileName = "tuihuochuku_jiangmen";
                //String fileName1 = "销售出库";

                String stockName = "";
                //String fileName1 = "销售出库";

                if (stockNo.equals("50301")) {
                    stockName = "零售仓";
                    fileName = "零售" + fileName;
                } else {
                    stockName = "批发仓";
                    fileName = "批发" + fileName;
                }


                fileName = fileName + format3.format(beginDate);
                fileName = "D:\\GDFiles\\Yj\\" + stockName + "\\" + fileName;


                // 2.创建dom对象
                Document document = DocumentHelper.createDocument();

                // 3.添加节点，根据需求添加，这里我只是设置了一个head节点，下面有name和age两个子节点
                Element head = document.addElement("jh", "http://cmsland.com/yjj_qyjk_thck.xsd");
                //head.addAttribute("xmlns", "http://cmsland.com/yjj_qyjk_pfck.xsd");
                for (Map<String, Object> map : saleYJHList) {
                    System.out.println(map.get("SALENO") == null ? "" : map.get("SALENO").toString());
                    String[] arr1 = new String[10];//有几列就写几
                    //如果数据不为空则赋值(这里就是循环每行的数据)
                    Element dj = head.addElement("dj");
                    dj.addAttribute("djbh", map.get("SALENO").toString());
                    dj.addAttribute("ckrq", format1.format(format2.parse(map.get("SALE_DATE").toString())));
                    dj.addAttribute("ghqy", map.get("VENCUS_NAME").toString());


                   // List<Map<String, Object>> saleYJDList = jmgdMapper.selectExcelReturnPurYJD(map.get("SALENO").toString(), format2.parse(map.get("SALE_DATE").toString()), map.get("STOCK_TYPE").toString());
                    String searchSaleno = map.get("SALENO").toString();
                    String stockType = map.get("STOCK_TYPE").toString();

                    String searchDate = format2.format(map.get("SALE_DATE"));
                    List<Map<String, Object>> result =  saleYJDList.stream()
                            .filter(row -> searchDate.equals(format2.format(row.get("SALE_DATE"))))
                            .filter(row -> searchSaleno.equals(row.get("SALENO")))
                            .filter(row -> stockType.equals(row.get("STOCK_TYPE"))).collect(Collectors.toList());


                    for (Map<String, Object> map1 : result) {
                        Element tm = dj.addElement("tm");
                        tm.addAttribute("bwm", map1.get("BWM") == null ? "" : map1.get("BWM").toString());
                        tm.addAttribute("bzgg", map1.get("WARE_SPEC") == null ? "" : map1.get("WARE_SPEC").toString());
                        tm.addAttribute("scph", map1.get("MAKENO") == null ? "" : map1.get("MAKENO").toString());
                        tm.addAttribute("scrq", map1.get("PROD_DATE") == null ? "" : format1.format(format2.parse(map1.get("PROD_DATE").toString())));
                        tm.addAttribute("yxqz", map1.get("VALID_DATE") == null ? "" : format1.format(format2.parse(map1.get("VALID_DATE").toString())));
                        tm.addAttribute("sl", map1.get("WARE_QTY") == null ? "" : map1.get("WARE_QTY").toString());
                        tm.addAttribute("xsdh", map1.get("SALENO") == null ? "" : map1.get("SALENO").toString());
                    }
/*

            arr1[0] = map.get("SALE_DATE") == null ? "" : format1.format(format2.parse(map.get("SALE_DATE").toString()));
            arr1[1] = map.get("SALENO") == null ? "" : map.get("SALENO").toString();
            arr1[2] = map.get("VENCUS_NAME") == null ? "" : map.get("VENCUS_NAME").toString();
            arr1[3] = map.get("SALER") == null ? "" : map.get("SALER").toString();
            arr1[4] = map.get("TRANS_TYPE") == null ? "" : map.get("TRANS_TYPE").toString();
            arr1[5] = map.get("CHENG_YUN_PERSON") == null ? "" : map.get("CHENG_YUN_PERSON").toString();
            arr1[6] = map.get("BEGIN_DATE") == null ? "" : format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
            arr1[7] = map.get("END_DATE") == null ? "" : format1.format(format2.parse(map.get("END_DATE").toString()));
            arr1[8] = map.get("STARTUP_TEMP") == null ? "" : map.get("STARTUP_TEMP").toString();
            arr1[9] = map.get("ARRI_TEMP") == null ? "" : map.get("ARRI_TEMP").toString();*/
                }


                // Element age = head.addElement("age");
                //age.addText("18");

                // 4、格式化模板
                //OutputFormat format = OutputFormat.createCompactFormat();
                OutputFormat format = OutputFormat.createPrettyPrint();
                format.setEncoding("GBK");

                // 5、生成xml文件
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                try {
                    XMLWriter writer = new XMLWriter(out, format);
                    writer.write(document);
                    writer.close();
                } catch (IOException e) {
                    System.out.println("生成xml文件失败。文件名【" + fileName + "】");
                }

                // 6、生成的XML文件
                // 7、利用文件输出流输出到文件， 文件输出到了您的项目根目录下了
                try (FileOutputStream fos = new FileOutputStream(fileName + ".xml")) {
                    fos.write(out.toByteArray());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            beginDate = dateAddOne(beginDate,1);

        }

        // System.out.println("生成采购退货xml文件成功");
    }


    @Override
    @Async
    public void createExcelStockYJ(Date beginDate) throws ParseException {
        stock(beginDate,"0");
        stock(beginDate,"50301");

    }


    private void stock(Date beginDate,String stockNo) throws ParseException {
        List<Map<String, Object>> saleYJHList = null;
        //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelSaleYJD(beginDate,endDate);

        if(stockNo.equals("50301")){
            saleYJHList = jmgdMapper.selectStock(beginDate,stockNo);
        }else{
            saleYJHList = jmgdMapper.selectStockN50301(beginDate,"50301");
        }

        if(saleYJHList.size()>0) {
            SimpleDateFormat format3 = new SimpleDateFormat("yyyyMMdd");

            SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");

            // 1.声明文件名称
            String fileName = "kucunjilu_jiangmen";
            //String fileName1 = "销售出库";

            String stockName = "";
            //String fileName1 = "销售出库";
            if (stockNo.equals("50301")) {
                stockName = "零售仓";
            } else {
                stockName = "批发仓";
            }


            fileName = fileName + format3.format(new Date());
            fileName = "D:\\GDFiles\\Yj\\" + stockName + "\\" + fileName;


            // 2.创建dom对象
            Document document = DocumentHelper.createDocument();

            // 3.添加节点，根据需求添加，这里我只是设置了一个head节点，下面有name和age两个子节点
            Element head = document.addElement("dj", "http://cmsland.com/yjj_qyjk_kc.xsd");
            //head.addAttribute("xmlns", "http://cmsland.com/yjj_qyjk_pfck.xsd");
            head.addAttribute("pdsj", saleYJHList.get(0).get("SALE_DATE") == null ? "" : format1.format(format2.parse(saleYJHList.get(0).get("SALE_DATE").toString())));

            if (saleYJHList.size() > 0) {
                String[] arr1 = new String[10];//有几列就写几
                //如果数据不为空则赋值(这里就是循环每行的数据)
                //Element dj = head.addElement("dj");
                //dj.addAttribute("pdsj",saleYJHList.get(0).get("SALE_DATE") == null ? "" : format1.format(format2.parse(saleYJHList.get(0).get("SALE_DATE").toString())));

                //List<Map<String,Object>> saleYJDList = jmgdMapper.selectExcelReturnSaleYJD(map.get("SALENO") == null ? "" : map.get("SALENO").toString());
                for (Map<String, Object> map1 : saleYJHList) {
                    Element tm = head.addElement("tm");
                    tm.addAttribute("bwm", map1.get("BWM") == null ? "" : map1.get("BWM").toString());
                    tm.addAttribute("bzgg", map1.get("WARE_SPEC") == null ? "" : map1.get("WARE_SPEC").toString());
                    tm.addAttribute("kcsl", map1.get("WARE_QTY") == null ? "" : map1.get("WARE_QTY").toString());
                    tm.addAttribute("scph", map1.get("MAKENO") == null ? "" : map1.get("MAKENO").toString());
                    tm.addAttribute("scrq", map1.get("PROD_DATE") == null ? "" : format1.format(format2.parse(map1.get("PROD_DATE").toString())));
                    tm.addAttribute("yxqz", map1.get("VALID_DATE") == null ? "" : format1.format(format2.parse(map1.get("VALID_DATE").toString())));
                }
/*

            arr1[0] = map.get("SALE_DATE") == null ? "" : format1.format(format2.parse(map.get("SALE_DATE").toString()));
            arr1[1] = map.get("SALENO") == null ? "" : map.get("SALENO").toString();
            arr1[2] = map.get("VENCUS_NAME") == null ? "" : map.get("VENCUS_NAME").toString();
            arr1[3] = map.get("SALER") == null ? "" : map.get("SALER").toString();
            arr1[4] = map.get("TRANS_TYPE") == null ? "" : map.get("TRANS_TYPE").toString();
            arr1[5] = map.get("CHENG_YUN_PERSON") == null ? "" : map.get("CHENG_YUN_PERSON").toString();
            arr1[6] = map.get("BEGIN_DATE") == null ? "" : format1.format(format2.parse(map.get("BEGIN_DATE").toString()));
            arr1[7] = map.get("END_DATE") == null ? "" : format1.format(format2.parse(map.get("END_DATE").toString()));
            arr1[8] = map.get("STARTUP_TEMP") == null ? "" : map.get("STARTUP_TEMP").toString();
            arr1[9] = map.get("ARRI_TEMP") == null ? "" : map.get("ARRI_TEMP").toString();*/
            }


            // Element age = head.addElement("age");
            //age.addText("18");

            // 4、格式化模板
            //OutputFormat format = OutputFormat.createCompactFormat();
            OutputFormat format = OutputFormat.createPrettyPrint();
            format.setEncoding("GBK");

            // 5、生成xml文件
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            try {
                XMLWriter writer = new XMLWriter(out, format);
                writer.write(document);
                writer.close();
            } catch (IOException e) {
                System.out.println("生成xml文件失败。文件名【" + fileName + "】");
            }

            // 6、生成的XML文件
            // 7、利用文件输出流输出到文件， 文件输出到了您的项目根目录下了
            try (FileOutputStream fos = new FileOutputStream(fileName + ".xml")) {
                fos.write(out.toByteArray());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //  System.out.println("生成仓库xml文件成功");
    }


    public static void main(String[] args){
        //System.out.println(dateAddOne(new Date()));


        Date begin = new Date();
        begin = dateAddOne(begin,-10);
        Date end = new Date();
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
       /* System.out.println(format1.format(begin));
        begin = dateAddOne(begin);

        System.out.println(format1.format(begin));*/


        while(begin.compareTo(end)<=0){
            System.out.println(format1.format(begin));
            begin = dateAddOne(begin,1);
        }


    }

    /*日期加+1天*/
    public static Date dateAddOne(Date date,int day) {
        Calendar   calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DATE,day); //把日期往后增加一天,整数  往后推,负数往前移动
        date=calendar.getTime(); //这个时间就是日期往后推一天的结果
        return date;

    }


}
